package com.walnut.servlet;

import com.walnut.dao.FoodDao;
import com.walnut.dao.OrderDao;
import com.walnut.dao.impl.FoodDaoImpl;
import com.walnut.dao.impl.OrderDaoImpl;
import com.walnut.pojo.Order;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/deleteOrder")
public class DeleteOrderServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = getServletContext();
        Integer goodsId = Integer.parseInt(request.getParameter("goodsId"));
        OrderDao orderDao = new OrderDaoImpl();
        try {
            int count=orderDao.delete(goodsId);
            if (count==1) {
                context.setAttribute("message","删除成功");
            }else {
                context.setAttribute("message","删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
